package com.bxy.dzsc.controller;

import com.bxy.dzsc.domain.Admin;
import com.bxy.dzsc.service.AdminService;
import com.bxy.dzsc.utilbeans.AdminLoginForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class AdminController {
    @Autowired
    private AdminService adminService;
    @RequestMapping("/adminLogin")
    @ResponseBody
    public String adminlogin(HttpSession session, @RequestBody AdminLoginForm adminLoginForm){
        String adminname=adminLoginForm.getAdminname();
        String password=adminLoginForm.getPassword();
        System.out.println(adminname);
        Admin admin = adminService.findbynameandpwd(adminname, password);
        if (admin !=null){
            session.setAttribute("admin",admin);
            System.out.println("登陆成功");
            String node=admin.getAdminname();
            return node;
        }else {
            System.out.println("登陆失败");
            String node=null;
            return node;
        }
    }
}
